package com.seeyon.apps.ddkk.form.workflowevent;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.seeyon.apps.ddkk.manager.DDKkDistributorManger;
import com.seeyon.apps.ddkk.manager.KkqxbManager;
import com.seeyon.apps.kk.form.workflowevent.KkBaseExtendPlug;
import com.seeyon.cap4.form.bean.FormBean;
import com.seeyon.cap4.form.bean.FormDataMasterBean;
import com.seeyon.cap4.form.bean.FormTableBean;
import com.seeyon.ctp.common.AppContext;
import com.seeyon.ctp.common.affair.manager.AffairManager;
import com.seeyon.ctp.common.constants.ApplicationCategoryEnum;
import com.seeyon.ctp.common.exceptions.BusinessException;
import com.seeyon.ctp.common.po.affair.CtpAffair;
import com.seeyon.ctp.workflow.event.WorkflowEventData;
public class DDKkDistributoronStepBack extends KkBaseExtendPlug {
	private static final Log log = LogFactory.getLog(DDKkDistributoronStepBack.class);
	
	
	private KkqxbManager kkqxbManager;
	private DDKkDistributorManger DDKkDistributorManger;
	
	public void setDDKkDistributorManger(DDKkDistributorManger dDKkDistributorManger) {
		DDKkDistributorManger = dDKkDistributorManger;
	}

	public void setKkqxbManager(KkqxbManager kkqxbManager) {
		this.kkqxbManager = kkqxbManager;
	}

	@Override
	public String getId() {
		// TODO Auto-generated method stub
		return "ddKkDistributoronStepBack";
	}

	@Override
	public String getLabel() {
		// TODO Auto-generated method stub
		return "DD回退底表日志记录";
	}

	public ApplicationCategoryEnum getAppName() {
		return ApplicationCategoryEnum.form;
	}
	//回退事件
    public void onStepBack(WorkflowEventData data){
		FormBean formBean = (FormBean) data.getBusinessData().get("formBean");
		FormDataMasterBean formDataMasterBean = (FormDataMasterBean) data.getBusinessData().get("formDataBean");
		FormTableBean formData = formDataMasterBean.getFormTable();// 获取表单bean对象
		AffairManager affairManager=(AffairManager) AppContext.getBean("affairManager");		
		try {
			CtpAffair affair=affairManager.get(data.getAffairId());
			String nodePolicy=affair.getNodePolicy();//节点名称
			if("so审核".equals(nodePolicy)||"HCC".equals(nodePolicy)){
				DDKkDistributorManger kkDistributor=(com.seeyon.apps.ddkk.manager.DDKkDistributorManger) AppContext.getBean("kkDistributor");
				kkDistributor.ddStopLog(formBean, formDataMasterBean,nodePolicy);
			}
		} catch (Exception e) {
			log.error("ddkk-回退日志底表写入异常：",e);
		}
    }
	
}
